import Router from 'koa-router'
import moment from 'moment'
import fs from 'fs'
const router = new Router()
router.post('/wowsLog', async (ctx, next) => {
  console.log(ctx.request.body)
  const data = { ...ctx.request.body }
  if (ctx.header['x-real-ip'] !== null) data.ip = ctx.header['x-real-ip']
  data.date = moment().format('YYYY-MM-DD HH:mm:ss')
  data['user-agent'] = ctx.header['user-agent']
  fs.appendFile('./wows.log', JSON.stringify(data) + '\n', (err) => {
    if (err !== null) throw err
  })
  ctx.body = data
})

export default router
